package com.fable.sp.core.util;

import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.springframework.stereotype.Component;

/**
 * .
 *
 * @author stormning on 16/7/4.
 */
@Component
public class HibernateContextIntegrator implements Integrator {

    @Override
    public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
        HibernateContext.configuration = configuration;
        HibernateContext.sessionFactory = sessionFactory;
        HibernateContext.serviceRegistry = serviceRegistry;
    }

    @Override
    public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
        HibernateContext.metadata = metadata;
        HibernateContext.sessionFactory = sessionFactory;
        HibernateContext.serviceRegistry = serviceRegistry;
    }

    @Override
    public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
        //do nothing
    }
}
